package com.ruoyi.location.controller;


import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.location.mapper.AddrMapper;
import com.ruoyi.location.pojo.Location;
import com.ruoyi.location.service.getLocation;
import com.ruoyi.location.utils.MyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@RequestMapping("/location")
public class AddrController {
    @Autowired
    private AddrMapper addr;
    @Autowired
    private TokenService ts;

    @GetMapping("/position/{imei}")
    AjaxResult getALLPosition(@PathVariable("imei") Long imei){
        List<Location> positions = addr.getPosition(imei);
        List<Location> pos = MyUtils.sortByDate(positions);   //对获得的List排序
        System.out.println(ts.getLoginUser());
        return AjaxResult.success(pos);
    }

    @PostMapping("/position/{imei}")
    AjaxResult getPositionByDate(@RequestBody String str ,@PathVariable("imei") Long imei){
        JSONObject js = JSONObject.parseObject(str);
        String startDate = js.getString("startDate");
        String endDate = js.getString("endDate");
        System.out.println(startDate);
        List<Location> positions = addr.getPosition(imei);
        List<Location> res = getLocation.choose(positions, startDate, endDate);
        return AjaxResult.success(res);
    }

}
